import random
from time import sleep
import uiautomation
import pyautogui

from tools.sjqd_way import write_data_from_excel


class fuwudengji():
        name = random.randrange(1,101)
        age = random.randrange(10,71)
        ID1 = random.randrange(1960,2024)
        ID2 = random.randrange(1000,9999)
        tel = random.randrange(10000000,999999999)
        his = uiautomation.WindowControl(searchDepth=1, Name='科玛奇医院信息管理系统')  # 锁定窗口
        xm = his.WindowControl(AutomationId='windFWDJ',Name='服务登记').EditControl(AutomationId='txtName', ClassName='TextBox') #姓名
        xb = his.WindowControl(AutomationId='windFWDJ',Name='服务登记').ButtonControl(AutomationId='PART_ToggleButton', ClassName='Button',foundIndex=2) #性别
        nl = his.WindowControl(AutomationId='windFWDJ',Name='服务登记').EditControl(AutomationId='tbNianling', ClassName='TextBox') #年龄
        SFID = his.WindowControl(AutomationId='windFWDJ',Name='服务登记').EditControl(AutomationId='txtSFZH', ClassName='TextBox') #身份证号码
        fwks = his.WindowControl(AutomationId='windFWDJ',Name='服务登记').EditControl(AutomationId='PART_TextBox', ClassName='TextBox',foundIndex=4) #服务科室
        ys = his.WindowControl(AutomationId='windFWDJ',Name='服务登记').EditControl(AutomationId='PART_TextBox', ClassName='TextBox',foundIndex=3) #医生
        dz = his.WindowControl(AutomationId='windFWDJ',Name='服务登记').EditControl(AutomationId='txtZhuZhi', ClassName='TextBox') #地址
        bc= his.WindowControl(AutomationId='windFWDJ',Name='服务登记').ButtonControl(AutomationId='savebtn', ClassName='Button') #保存
        gb = his.WindowControl(AutomationId='windFWDJ',Name='服务登记').ButtonControl(Name='关闭', ClassName='Button') #关闭
        cz= his.WindowControl(AutomationId='windFWDJ',Name='服务登记').ButtonControl(AutomationId='clearbtn', ClassName='Button') #重置

#输入姓名
        def input_name(self):
                self.xm.SendKeys('测试患者{}'.format(self.name))
                sleep(0.5)
                pyautogui.hotkey('ctrl', 'a')
                pyautogui.hotkey('ctrl', 'c')

#选择性别
        def choose_sex(self):
                self.xb.Click()
                pyautogui.keyDown('down')
                pyautogui.press('enter')
        # def choose_nan(self):
        #         self.xb.Click()
        #         pyautogui.keyDown('down')
        #         pyautogui.press('enter')
        # #女
        # def choose_nv(self):
        #         self.xb.Click()
        #         pyautogui.keyDown('down')
        #         pyautogui.keyDown('down')
        #         pyautogui.press('enter')

#输入年龄
        def input_age(self):
                self.nl.SendKeys('{}'.format(self.age))

#输入身份证号码
        def input_id(self):
                self.SFID.SendKeys("510623{}0909{}".format(self.ID1,self.ID2))
#输入电话号码
        def input_tel(self):
                self.SFID.Click()
                pyautogui.press('tab')
                pyautogui.typewrite('159{}'.format(self.tel))
#选择服务科室
        def choose_fwks(self,fwks):
                fwks1 = str(fwks)
                self.fwks.DoubleClick()
                self.fwks.SendKeys(fwks1)
                # self.fwks.SendKeys(fwks1)
                pyautogui.press('enter')

#选择医生
        def choose_ys(self,doctor):
                doctor1 = doctor
                self.ys.DoubleClick()
                self.ys.SendKeys(doctor1)
                pyautogui.press('enter')

#输入地址
        def input_dz(self,adress):
                self.dz.SendKeys(adress)

#点击保存
        def click_bc_btn(self):
                self.bc.Click()

#点击关闭
        def click_gb_btn(self):
                self.gb.Click()


#创建多个患者
        def creat_hz(self,fwks,doctor,adress):
                fwks1 = str(fwks)
                doctor1 = str(doctor)
                adress1 = str(adress)
                self.xm.Click()
                self.xm.SendKeys('测试患者{}'.format(self.name))
                # pyautogui.hotkey('ctrl', 'a')
                # pyautogui.hotkey('ctrl', 'c')
                ceshihuanzhe = self.xm.GetValuePattern().Value
                write_data_from_excel(ceshihuanzhe)
                sleep(1)
                self.xb.Click()
                sleep(1)
                pyautogui.keyDown('down')
                pyautogui.press('enter')
                sleep(1)
                self.SFID.SendKeys("510623{}0909{}".format(self.ID1, self.ID2))
                self.SFID.Click()
                pyautogui.press('tab')
                sleep(1)
                pyautogui.typewrite('159{}'.format(self.tel))
                sleep(1)
                self.fwks.DoubleClick()
                self.fwks.SendKeys(fwks1)
                sleep(1)
                pyautogui.press('enter')
                self.ys.DoubleClick()
                self.ys.SendKeys(doctor1)
                sleep(1)
                pyautogui.press('enter')
                self.dz.SendKeys(adress1)
                self.bc.Click()
                self.gb.Click()
                sleep(2)
